import pymysql


def creat_connection():
    """
    创建数据库连接
    :return:connection
    """
    connection = pymysql.connect(
        user='root',
        password="Admin_123",
        host='localhost',
        database='toutiao',
        unix_socket=None,
        port=3306,

    )
    return connection


def execute_sql(sql):
    """
    创建游标，执行sql，关闭游标，关闭连接
    :param sql:
    :return:返回执行结果
    """
    # 创建链接
    conn = creat_connection()
    # 创建游标
    cursor = conn.cursor()
    # 执行sql
    cursor.execute(sql)
    # 提取
    result = cursor.fetchall()
    cursor.close()
    conn.close()
    return result
